import createjs from 'createjs-ts'
import cjs=createjs
export default class ClickHelper{
    private target: any;
    private mouseDownHandle:any;
    constructor(target:cjs.DisplayObject,clickCallback:any){
        this.target=target;
        this.mouseDownHandle=target.on("mousedown",(e:cjs.MouseEvent)=>{
            //console.log('mousedown')
            const time=new Date().getTime()
            const stageMouseUpHandle=target.stage.on('stagemouseup',()=>{
                //target.stage.off('pressmove',stageMouseMoveHandle)
                target.stage.off('stagemouseup',stageMouseUpHandle)
                //target.off('mousedown',mouseDownHandle)
                //endDrag&&endDrag(target);
                if(new Date().getTime()-time<300){
                    clickCallback&&clickCallback(target)
                }
            })
        });
    }
    //销毁
    destroy():void{
        this.target.off('mousedown',this.mouseDownHandle)
    }
}